import { NextResponse } from 'next/server';
import { getServerSession } from 'next-auth/next';
import { authOptions } from '@/app/api/auth/[...nextauth]/route';
import { api } from '@/lib/apiService';

export async function POST(request) {
  try {
    const session = await getServerSession(authOptions);
    if (!session?.user?.email) {
      return NextResponse.json({ error: '未授权' }, { status: 401 });
    }
    const body = await request.json();
    console.log('Request body:', JSON.stringify(body, null, 2));
    const data = await api.auth.post(`prompts/updatePromptsById`, body);
    return NextResponse.json(data);
  } catch (error) {
    console.error('Server error:', error);
    console.error('Error details:', error.response?.data || error.message);
    return NextResponse.json({ 
      error: error.message,
      details: error.response?.data || error.cause || 'Unknown error'
    }, { status: 500 });
  }
}


